package org.rox.hephantan.bai3;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Client {
	public static void main(String[] args) {
		Socket socket;
		BufferedReader reader, stdIN;
		PrintWriter writer;
		String data;
		try {
			socket = new Socket("localhost", 2002);
			reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			writer = new PrintWriter(socket.getOutputStream(), true);
			
			System.out.print("Enter a message: ");
			stdIN  = new BufferedReader(new InputStreamReader(System.in));
			data = stdIN.readLine();
			writer.println(data);
			
			while ((data = reader.readLine()) != null)
			System.out.println("Result returned from Server: " + data);
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}
